<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ include file="navbar.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>My JSP 'singlefile.jsp' starting page</title>
	<link rel="stylesheet" type="text/css" href="styles/css/bootstrap.min.css" />
  </head>
  
  <body class="body">
    <div class="container" style="margin-top:60px;width:960px;margin-left:auto;margin-right:auto;">

	  <div class="row">
	
	
		<!-- 导入左侧部分 -->
		<jsp:include page="side.jsp">
			<jsp:param value="file" name="tag"/>
		</jsp:include>
		
		
		<div class="span9">
			
			

			<a href="file.jspx?m=upload&id=${requestScope.folder.folderId }" class="btn btn-primary" style="float:right"><i class="icon-white  icon-share"></i>上传资料</a>

			<div class="clear" style="margin-top:45px"></div>
			
			<ul class="breadcrumb" style="margin-bottom:0px;border-radius: 3px 3px 0 0;margin-top:15px">
				<li class="active">
					<i class="icon-th"></i><a href="file.jspx">文件共享</a>>${requestScope.folder.folderName }
				</li>
				
				<c:choose>
					<c:when test="${requestScope.folder.fileNum == 0 }">
						<li style="float:right"><a  href="file.jspx?m=delFolder&id=${requestScope.folder.folderId}" ><i class="icon-trash" class="pull-right" ></i></a></li>
					</c:when>
					<c:otherwise>
						<li style="float:right"><a  href="#myModal2" data-toggle="modal" ><i class="icon-trash" class="pull-right" ></i></a></li>
					</c:otherwise>
				</c:choose>
				
				
				
			</ul>

			<div class="wall">
				<table class="table table-striped">
					<thead>
						<tr>
							<th width="30px"></th>
							<th width="30%">名称</th>
							<th width="30%">大小</th>
							<th>创建人</th>
							<th ></th>
						</tr>
					</thead>
					<tbody>
					
						<c:forEach items="${requestScope.filepage.result }" var="f">
						<tr>
							<td>
								<c:choose>
									<c:when test="${f.fileType.typeName == '.doc' }">
										<img src="styles/img/word.png"/>
									</c:when>
									<c:when test="${f.fileType.typeName == '.xls' }">
										<img src="styles/img/excel.png"/>
									</c:when>
									<c:when test="${f.fileType.typeName == '.pdf' }">
										<img src="styles/img/pdf.png"/>
									</c:when>
									<c:when test="${f.fileType.typeName == '.gif' }">
										<img src="styles/img/gif.png"/>
									</c:when>
									<c:when test="${f.fileType.typeName == '.mp3' }">
										<img src="styles/img/mp3.png"/>
									</c:when>
									<c:when test="${f.fileType.typeName == '.zip' }">
										<img src="styles/img/zip.png"/>
									</c:when>
									<c:when test="${f.fileType.typeName == '.png' }">
										<img src="styles/img/png.png"/>
									</c:when>
									<c:when test="${f.fileType.typeName == '.txt' }">
										<img src="styles/img/txt.png"/>
									</c:when>
									<c:when test="${f.fileType.typeName == '.ppt' }">
										<img src="styles/img/ppt.png"/>
									</c:when>
									<c:when test="${f.fileType.typeName == '.chm' }">
										<img src="styles/img/chm.png"/>
									</c:when>
									<c:when test="${f.fileType.typeName == '.html' }">
										<img src="styles/img/html.png"/>
									</c:when>
									
								</c:choose>
								
							</td>
							<td><a href="file.jspx?m=download&name=${f.name}">${f.fileName }${f.fileType.typeName }</a></td>

							<td>
								<c:choose>
									<c:when test="${f.fileSize < 1024 }">
									<fmt:formatNumber  type="number" value="${f.fileSize }"></fmt:formatNumber>B
									</c:when>
									<c:when test="${f.fileSize >= 1024 &&f.fileSize < 1048576 }">
										<fmt:formatNumber  type="number" value="${f.fileSize/1024 }" pattern="#0.0"></fmt:formatNumber>K	
									</c:when>
									<c:when test="${f.fileSize >= 1048576 &&f.fileSize < 1073741824 }">
										<fmt:formatNumber  type="number" value="${f.fileSize/1048576 }" pattern="#0.0"></fmt:formatNumber>M
									</c:when>
									<c:when test="${f.fileSize >= 1073741824 &&f.fileSize < 1099511627776 }">
										<fmt:formatNumber  type="number" value="${f.fileSize/1073741824 }" pattern="#0.0"></fmt:formatNumber>G
									</c:when>
									<c:otherwise>
										<fmt:formatNumber  type="number" value="${f.fileSize/1073741824*1024 }" pattern="#0.0"></fmt:formatNumber>T
									</c:otherwise>
								</c:choose>
							</td>	
								
							<td>${f.user.userName }</td>
							
							
							
							<!-- 只有上传者本人才有资格删除自己的文件 -->
							<c:choose>
								<c:when test="${f.user.userName == sessionScope.user.userName }">
									<td ><a  href="#myModal1" data-toggle="modal" ><i class="icon-trash" class="pull-right" ></i></a></td>
								</c:when>
								<c:otherwise>
									<td></td>
								</c:otherwise>
							</c:choose>
							
						
							
						</tr>
						
						
						
						
					<!-- 以下部分为隐藏层，当点击删除时会提示 -->
					<div id="myModal1" class="modal hide fade" style="display: none;">
					    <div class="modal-header">
						    <a class="close" data-dismiss="modal">×</a>
						    	<h3>亲……您真的要删除该文件吗？</h3>
						</div>
					    <div class="modal-body">
					   		 <p style="color:red;">文件一旦删除将不可恢复，请三思而后行啊亲！</p>
					    </div>
					    <div class="modal-footer">
					   		<a href="file.jspx?m=delFile&id=${f.fileId}&folderId=${f.folder.folderId }" class="btn btn-primary">确定</a>
					    	<a class="btn" data-dismiss="modal" href="#">取消</a>
					    </div>
				   </div>
				   
				   
				   
				   <div id="myModal2" class="modal hide fade" style="display: none;">
					    <div class="modal-header">
						    <a class="close" data-dismiss="modal">×</a>
						    	<h3>亲……您无法删除该文件夹！</h3>
						</div>
					    <div class="modal-body">
					   		 <p style="color:green;">只有当文件夹不包含文件时，才可以删除！</p>
					    </div>
					    <div class="modal-footer">
					   		
					    	<a class="btn btn-primary" data-dismiss="modal" href="#">确定</a>
					    </div>
				   </div>
						
						
						</c:forEach>
					</tbody>
				</table>
				  
				
				<!--以下是分页功能，在页面显示靠右时使用 pagination-right而不是pull-right -->
			    <div class="pagination pagination-right">
				    <ul>
				    	<c:choose>
					  		<c:when test="${requestScope.filepage.pageNum == 1 }">
					  			 <li><a href="#">首页</a></li>
					  		</c:when>
					  		<c:otherwise>
					  			<li><a href="file.jspx?m=file&id=${requestScope.folder.folderId }&p=1">首页</a></li>
					  		</c:otherwise>
					  	</c:choose>
					  	<c:choose>
					  		<c:when test="${requestScope.filepage.pageNum == 1}">
					  			<li><a href="#">上一页</a></li>
					  		</c:when>
					  		<c:otherwise>
					  			<li><a href="file.jspx?m=file&id=${requestScope.folder.folderId }&p=${requestScope.filepage.pageNum - 1 }">上一页</a></li>
					  		</c:otherwise>
					  	</c:choose>
					  	<c:choose>
					  		<c:when test="${requestScope.filepage.pageNum == requetScope.filepage.totalPages }">
					  			<li><a href="#">下一页</a></li>
					  		</c:when>
					  		<c:otherwise>
					  			<li><a href="file.jspx?m=file&id=${requestScope.folder.folderId }&p=${requestScope.filepage.pageNum + 1 }">下一页</a></li>
					  		</c:otherwise>
					  	</c:choose>
					  	<c:choose>
					  		<c:when test="${requestScope.filepage.pageNum == requestScope.filepage.totalPages }">
					  			<li><a href="#">尾页</a></li>
					  		</c:when>
					  		<c:otherwise>
					  			<li><a href="file.jspx?m=file&id=${requestScope.folder.folderId }&p=${requestScope.filepage.totalPages }">尾页</a></li>
					  		</c:otherwise>
					  	</c:choose>
					   
					   
				    </ul>
				     <a href="file.jspx" class="btn" id="back">返回</a>		
				    </div>		
				    
				  
			</div>
			
			
		</div>
	  </div>
	</div>
	
				
	
	
	<script type="text/javascript" src="styles/jquery/jquery.js"></script>
	<script type="text/javascript" src="styles/js/bootstrap.min.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			$("#showModal1").click(function(){
				$("#myModal1").modal();
				
			});
			
			$("#showModal2").click(function(){
				$("#myModal2").modal();
				
			});
		});
	</script>
  </body>
</html>
